{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Greatest English Letter in Upper and Lower Case"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #hash-table #string #enumeration"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #哈希表 #字符串 #枚举"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: greatestLetter"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #兼具大小写的最好英文字母"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你一个由英文字母组成的字符串 <code>s</code> ，请你找出并返回 <code>s</code> 中的 <strong>最好</strong> 英文字母。返回的字母必须为大写形式。如果不存在满足条件的字母，则返回一个空字符串。</p>\n",
    "\n",
    "<p><strong>最好</strong> 英文字母的大写和小写形式必须 <strong>都</strong> 在 <code>s</code> 中出现。</p>\n",
    "\n",
    "<p>英文字母 <code>b</code> 比另一个英文字母&nbsp;<code>a</code>&nbsp;<strong>更好</strong> 的前提是：英文字母表中，<code>b</code> 在 <code>a</code> 之 <strong>后</strong> 出现。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>s = \"l<em><strong>Ee</strong></em>TcOd<em><strong>E</strong></em>\"\n",
    "<strong>输出：</strong>\"E\"\n",
    "<strong>解释：</strong>\n",
    "字母 'E' 是唯一一个大写和小写形式都出现的字母。</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>s = \"a<em><strong>rR</strong></em>AzFif\"\n",
    "<strong>输出：</strong>\"R\"\n",
    "<strong>解释：</strong>\n",
    "字母 'R' 是大写和小写形式都出现的最好英文字母。\n",
    "注意 'A' 和 'F' 的大写和小写形式也都出现了，但是 'R' 比 'F' 和 'A' 更好。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 3：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>s = \"AbCdEfGhIjK\"\n",
    "<strong>输出：</strong>\"\"\n",
    "<strong>解释：</strong>\n",
    "不存在大写和小写形式都出现的字母。\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>1 &lt;= s.length &lt;= 1000</code></li>\n",
    "\t<li><code>s</code> 由小写和大写英文字母组成</li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [greatest-english-letter-in-upper-and-lower-case](https://leetcode.cn/problems/greatest-english-letter-in-upper-and-lower-case/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [greatest-english-letter-in-upper-and-lower-case](https://leetcode.cn/problems/greatest-english-letter-in-upper-and-lower-case/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['\"lEeTcOdE\"', '\"arRAzFif\"', '\"AbCdEfGhIjK\"']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        s = set(s)\n",
    "        for lower, upper in zip(reversed(ascii_lowercase), reversed(ascii_uppercase)):\n",
    "            if lower in s and upper in s:\n",
    "                return upper\n",
    "        return \"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        cnt_small = [0]*26\n",
    "        cnt_big = [0]*26\n",
    "        for x in s:\n",
    "            c = ord(x)\n",
    "            if c>=97:cnt_small[c-97] = 1\n",
    "            else:cnt_big[c-65] = 1\n",
    "        res = None\n",
    "        for i in range(26-1,-1,-1):\n",
    "            if cnt_small[i] and cnt_big[i]:\n",
    "                res = i\n",
    "                break\n",
    "        return chr(65+res) if res!=None else ''\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        s = set(s)\n",
    "        for lower, upper in zip(reversed(ascii_lowercase), reversed(ascii_uppercase)):\n",
    "            if lower in s and upper in s:\n",
    "                return upper\n",
    "        return \"\"\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        mask1 = mask2 = 0\n",
    "        for c in s:\n",
    "            if c.islower():\n",
    "                mask1 |= 1 << (ord(c) - ord(\"a\"))\n",
    "            else:\n",
    "                mask2 |= 1 << (ord(c) - ord(\"A\"))\n",
    "        mask = mask1 & mask2\n",
    "        return chr(mask.bit_length() - 1 + ord(\"A\")) if mask else \"\"\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        hash_set = set(s)\n",
    "        res = ''\n",
    "        for i in reversed([chr(i) for i in range(97,123)]):\n",
    "            if i in hash_set and i.upper() in hash_set:\n",
    "                return i.upper()\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        best_char = \"\"\n",
    "        for c in s:\n",
    "            if chr(ord(c) + 32) in s:\n",
    "                best_char = max(best_char, c)\n",
    "        return best_char"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        s = set(s)\n",
    "        for lower, upper in zip(reversed(ascii_lowercase), reversed(ascii_uppercase)):\n",
    "            if lower in s and upper in s:\n",
    "                return upper\n",
    "        return \"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        S=set(s)\n",
    "        upperlist=['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']\n",
    "        for c in upperlist[::-1]:\n",
    "            if c in S and c.lower() in S:\n",
    "                return c\n",
    "        return ''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        ns,save = sorted(s),set(s)\n",
    "        for i in ns[::-1]:\n",
    "            if i.lower() in save and i.upper() in save:\n",
    "                return i.upper()\n",
    "        return ''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        for c in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'[::-1]:\n",
    "            c1 = chr(ord(c) + 32)\n",
    "            if c in s and c1 in s:\n",
    "                return c\n",
    "        return ''\n",
    "        \n",
    "                \n",
    "        \n",
    "                    \n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        number=0\n",
    "        for letter in s:\n",
    "            if letter.upper() in s and letter.lower() in s:\n",
    "                number=max(number,ord(letter.upper()))\n",
    "        if number==0:\n",
    "            return ''\n",
    "        else:\n",
    "            return chr(number)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        s = set(s)\n",
    "        for lower, upper in zip(reversed(ascii_lowercase), reversed(ascii_uppercase)):\n",
    "            if lower in s and upper in s:\n",
    "                return upper\n",
    "        return \"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        appeared = set()\n",
    "        good = set()\n",
    "        for c in s:\n",
    "            appeared.add(c)\n",
    "            if c.swapcase() in appeared:\n",
    "                good.add(c.upper())\n",
    "        return '' if not good else max(good)\n",
    "                "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        # s = set(s)\n",
    "        # for lower, upper in zip(reversed(ascii_lowercase), reversed(ascii_uppercase)):\n",
    "        #     if lower in s and upper in s:\n",
    "        #         return upper\n",
    "        # return \"\"\n",
    "        mask = 0\n",
    "        for si in s:\n",
    "            mask |= 1 << (ord(si) - ord('A'))\n",
    "        mask &= mask >> (ord('a') - ord('A'))\n",
    "        return chr(ord('A')+mask.bit_length()-1) if mask != 0 else ''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        ss = set(s)\n",
    "        for c in ascii_uppercase[::-1]:\n",
    "            if c in ss and c.lower() in ss:\n",
    "                return c\n",
    "        return ''\n",
    "\n",
    "\n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        s = set(s)\n",
    "        for lower, upper in zip(reversed(ascii_lowercase), reversed(ascii_uppercase)):\n",
    "            if lower in s and upper in s:\n",
    "                return upper\n",
    "            \n",
    "        return \"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        t=''\n",
    "        for i in s:\n",
    "            if i.islower() and i.upper() in s:\n",
    "                t=max(t,i.upper())\n",
    "        return t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        res = []\n",
    "        for i in s:\n",
    "            res.append(ord(i))\n",
    "        ans = 0\n",
    "        for j in res:\n",
    "            if j+32 in res:\n",
    "                if j>ans:\n",
    "                    ans = j\n",
    "        if ans == 0:\n",
    "            return \"\"\n",
    "        return chr(ans)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        ans = 'A'\n",
    "        flag = 0\n",
    "        for ch in s:\n",
    "            if ch.isupper() and ch.lower() in s:\n",
    "                flag = 1\n",
    "                if ord(ch) > ord(ans):\n",
    "                    ans = ch\n",
    "            elif ch.islower() and ch.upper() in s:\n",
    "                flag = 1\n",
    "                if ord(ch.upper()) > ord(ans):\n",
    "                    ans = ch.upper()\n",
    "        return ans if flag else \"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "\n",
    "        ss = set(s)\n",
    "\n",
    "        for c in ascii_uppercase[::-1]:\n",
    "\n",
    "            if c in ss and c.lower() in ss:\n",
    "\n",
    "                return c\n",
    "\n",
    "        return ''\n",
    "\n",
    "\n",
    "\n",
    "                \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        ss = set(s)\n",
    "        for c in ascii_uppercase[::-1]:\n",
    "            if c in ss and c.lower() in ss:\n",
    "                return c\n",
    "        return \"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        hash_set = set(s)\n",
    "        res = ''\n",
    "        for i in reversed([chr(i) for i in range(97,123)]):\n",
    "            if i in hash_set and i.upper() in hash_set:\n",
    "                return i.upper()\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        s2 = []\n",
    "        for i in range(len(s)):\n",
    "            if 'A'<=s[i]<='Z':\n",
    "                s2.append(ord(s[i])-ord('A')+1+100)\n",
    "            if 'a'<=s[i]<='z':\n",
    "                s2.append(ord(s[i])-ord('a')+1)\n",
    "        s2.append(0)\n",
    "        res = -1\n",
    "        for i in range(len(s2)):\n",
    "            if s2[i] > 100:\n",
    "                for j in range(len(s2)):\n",
    "                    if s2[i]-100 == s2[j] and s2[i]>s2[res]:\n",
    "                        res = i\n",
    "        return '' if res == -1 else s[res]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        lower = upper = 0\n",
    "        for ch in s:\n",
    "            if ch.islower():\n",
    "                lower |= (1 << ord(ch) - ord('a'))\n",
    "            elif ch.isupper():\n",
    "                upper |= (1 << ord(ch) - ord('A'))\n",
    "\n",
    "        for i in range(25,-1,-1):\n",
    "            if (lower & upper & (1 << i)):\n",
    "                return chr(ord('A') + i)\n",
    "        return ''\n",
    "        # s = set(s)\n",
    "        # for lower, upper in zip(reversed(ascii_lowercase), reversed(ascii_uppercase)):\n",
    "        #     if lower in s and upper in s:\n",
    "        #         return upper\n",
    "        # return \"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        s=set(s)\n",
    "        for lower,upper in zip(reversed(ascii_lowercase),reversed(ascii_uppercase)):\n",
    "            if lower in s and upper in s:\n",
    "                return upper\n",
    "        return \"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        upper = lower = 0;\n",
    "        for c in s:\n",
    "            if ord(c) < 97:\n",
    "                upper |= 1 << (ord(c) - 65);\n",
    "            else:\n",
    "                lower |= 1 << (ord(c) - 97);\n",
    "        \n",
    "        for i in range(25, -1, -1):\n",
    "            if upper & lower & (1 << i):\n",
    "                return chr(65 + i);\n",
    "\n",
    "        return \"\";"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        ss = set(s)\n",
    "        for c in ascii_uppercase[::-1]:\n",
    "            if c in ss and c.lower() in ss:\n",
    "                return c\n",
    "        return ''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        ss = set(s)\n",
    "        for c in ascii_uppercase[::-1]:\n",
    "            if c in ss and c.lower() in ss:\n",
    "                return c\n",
    "        return \"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        mask1 = mask2 = 0\n",
    "        for c in s:\n",
    "            if c.islower():\n",
    "                mask1 |= 1 << (ord(c) - ord(\"a\"))\n",
    "            else:\n",
    "                mask2 |= 1 << (ord(c) - ord(\"A\"))\n",
    "        mask = mask1 & mask2\n",
    "        return chr(mask.bit_length() - 1 + ord(\"A\")) if mask else \"\"\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        ans = ''\n",
    "        for i in range(26):\n",
    "            if chr(ord('a')+i) in s and chr(ord('A')+i) in s :\n",
    "                ans = chr(ord('A')+i)\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        return max(ans) if (ans := [c for c in string.ascii_uppercase if c in s and c.lower() in s]) else \"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        a=[\"A\",\"B\",\"C\",\"D\",\"E\",\"F\",\"G\",\"H\",\"I\",\"J\",\"K\",\"L\",\"M\",\"N\",\"O\",\"P\",\"Q\",\"R\",\"S\",\"T\",\n",
    "        \"U\",\"V\",\"W\",\"X\",\"Y\",\"Z\"]\n",
    "        b=[\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\",\"h\",\"i\",\"j\",\"k\",\"l\",\"m\",\"n\",\"o\",\"p\",\"q\",\"r\",\"s\",\"t\",\n",
    "        \"u\",\"v\",\"w\",\"x\",\"y\",\"z\"]\n",
    "        n=25\n",
    "        while True:\n",
    "            if a[n] in s and b[n] in s:\n",
    "                return a[n]\n",
    "            n-=1\n",
    "            if n==-1:\n",
    "                return \"\"\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        for i in range(90,64,-1):\n",
    "            if chr(i) in s and chr(i+32) in s:\n",
    "                return chr(i)\n",
    "        return \"\" "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        hax = set(s)\n",
    "        res = ''\n",
    "        for x in hax:\n",
    "            if x.islower() and x.upper() in hax:\n",
    "                res = x.upper() if not res else max(x.upper(), res)\n",
    "            elif x.isupper() and x.lower() in hax:\n",
    "                res = x if not res else max(res, x)\n",
    "        return res\n",
    "\n",
    "                \n",
    "            \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        ss = set(s) \n",
    "        for i in ascii_uppercase[::-1]:\n",
    "            if i in ss and i.lower() in ss:\n",
    "                return i\n",
    "        return \"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        for c in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'[::-1]:\n",
    "            c1 = chr(ord(c) + 32)\n",
    "            if c in s and c1 in s:\n",
    "                return c\n",
    "        return ''\n",
    "        \n",
    "                \n",
    "        \n",
    "                    \n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        s=set(s)\n",
    "        for lower,upper in zip(reversed(ascii_lowercase),reversed(ascii_uppercase)):\n",
    "            if lower in s and upper in s :\n",
    "                return upper\n",
    "        return \"\"\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        s = set(s)\n",
    "        for lower , upper in zip(reversed(ascii_lowercase) , reversed(ascii_uppercase)):\n",
    "            if lower in s and upper in s:\n",
    "                return upper\n",
    "        return \"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        ans=[]\n",
    "        for i in s:\n",
    "            if \"a\"<=i<=\"z\" and i.upper() in s:\n",
    "                ans.append(i.upper())\n",
    "        return max(ans) if ans else \"\"\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        arr = list(set(s))\n",
    "        result = 0\n",
    "        for x in arr:\n",
    "            x = ord(x)\n",
    "            if 65 <= x <=90 and chr(x+32) in arr and x > result:\n",
    "                result = x\n",
    "        if result == 0:\n",
    "            return \"\"\n",
    "        return chr(result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        now=''\n",
    "        for t in s:\n",
    "            if 'A' <=t and t <='Z':\n",
    "                if chr(ord(t)+32) in s and t>now:\n",
    "                    now=t\n",
    "        return  now\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        a=[]\n",
    "        for i in str(set(s)):\n",
    "            if i.lower() in s and i.upper() in s:\n",
    "                a.append(i.upper())\n",
    "        a.sort()\n",
    "        return a[-1] if a!=[] else \"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        tmp = [i for i in s if i != ' ']\n",
    "        res = sorted(tmp)\n",
    "        for i in range(len(res)-1,0,-1):\n",
    "            if res[i].upper() in res and res[i].islower():\n",
    "                return res[i].upper()\n",
    "        return \"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        for i in range(25, -1, -1):\n",
    "            temp1 = chr(ord('a') + i)\n",
    "            temp2 = chr(ord('A') + i)\n",
    "            if temp1 in s and temp2 in s:\n",
    "                return temp2\n",
    "        return ''\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        s = set(s)\n",
    "        for lower, upper in zip(reversed(ascii_lowercase), reversed(ascii_uppercase)):\n",
    "            if lower in s and upper in s:\n",
    "                return upper\n",
    "        return \"\"\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        s=set(list(s))\n",
    "        for i in range(25,-1,-1):\n",
    "            if chr(ord(\"a\")+i) in s and chr(ord(\"A\")+i) in s:\n",
    "                return (chr(ord(\"A\")+i))\n",
    "        return \"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        ss = sorted(list(set(list(s.lower()))),reverse=True)\n",
    "        for ch in ss:\n",
    "            if ch in s and ch.upper() in s:\n",
    "                return ch.upper()\n",
    "        return \"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        a=''\n",
    "        for i in s:\n",
    "            if 'a'<=i<='z' and i.upper() in s:\n",
    "                if a=='' or i.upper()>a:\n",
    "                    a=i.upper()\n",
    "        return a\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        alp=''\n",
    "        for i in s:\n",
    "            if 'a'<=i<='z' and i.upper() in s:\n",
    "                if alp=='' or i.upper()>alp:\n",
    "                    alp=i.upper()\n",
    "        return alp\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        mask1 = mask2 = 0\n",
    "        for c in s:\n",
    "            if c.islower():\n",
    "                mask1 |= 1 << (ord(c) - ord(\"a\"))\n",
    "            else:\n",
    "                mask2 |= 1 << (ord(c) - ord(\"A\"))\n",
    "        mask = mask1 & mask2\n",
    "        return chr(mask.bit_length() - 1 + ord(\"A\")) if mask else \"\"\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        ss = set(s)\n",
    "        for c in ascii_uppercase[::-1]:\n",
    "            if c in ss and c.lower() in ss:\n",
    "                return c\n",
    "        return \"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        s = set(s)\n",
    "        for lower, upper in zip(reversed(ascii_lowercase), reversed(ascii_uppercase)):\n",
    "            if lower in s and upper in s:\n",
    "                return upper\n",
    "        return \"\"\n",
    "\n",
    " "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        s2 = [0]\n",
    "        res = 0\n",
    "        for i in range(len(s)):\n",
    "            if 'A'<=s[i]<='Z':\n",
    "                s2.append(ord(s[i])-ord('A')+1+100)\n",
    "                for j in range(len(s2)):\n",
    "                    if s2[i+1]-100 == s2[j] and s2[i+1]>s2[res]:\n",
    "                        res = i+1\n",
    "            if 'a'<=s[i]<='z':\n",
    "                s2.append(ord(s[i])-ord('a')+1)\n",
    "                for j in range(len(s2)):\n",
    "                    if s2[i+1] == s2[j]-100 and s2[j]>s2[res]:\n",
    "                        res = j\n",
    "        return '' if res == 0 else s[res-1]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        for i in range(25, -1, -1):\n",
    "            a, b = chr(i + ord('a')), chr(i + ord('A')),\n",
    "            if a in s and b in s:\n",
    "                return b\n",
    "\n",
    "        return ''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        list1 = []\n",
    "        for i in range(len(s)):\n",
    "            if s[i].islower():\n",
    "                if s[i].upper() in s:\n",
    "                    if s[i].upper() not in list1:\n",
    "                        list1.append(s[i].upper())\n",
    "            else:\n",
    "                if s[i].lower() in s:\n",
    "                    if s[i] not in list1:\n",
    "                        list1.append(s[i])\n",
    "        list1 = sorted(list1)\n",
    "        if len(list1)==0:\n",
    "            return \"\"\n",
    "        else:\n",
    "            return list1[-1]\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        ss=set(s)\n",
    "        for lower,upper in zip(reversed(ascii_lowercase),reversed(ascii_uppercase)):\n",
    "            if lower in s and upper in s :\n",
    "                return upper\n",
    "        return \"\"\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        lis=[]\n",
    "        for daxie in s:\n",
    "            ascdaxie=ord(daxie)\n",
    "            if ascdaxie>=65:\n",
    "                if chr(ascdaxie+32) in s:\n",
    "                    lis.append(daxie)\n",
    "        lis.sort()\n",
    "        if len(lis)==0:\n",
    "            return \"\"\n",
    "        else:\n",
    "            return lis[-1]\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "from collections import defaultdict\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        bestChar = ''\n",
    "        charMap = defaultdict(int)\n",
    "\n",
    "        for i in s:\n",
    "            j = i.upper()\n",
    "            if i.islower():\n",
    "                charMap[j] |= 1\n",
    "            else:\n",
    "                charMap[j] |= 2\n",
    "            \n",
    "            if charMap[j] == 3:\n",
    "                if bestChar == '' or ord(j) > ord(bestChar):\n",
    "                    bestChar = j\n",
    "        \n",
    "        return bestChar\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        tmp = []\n",
    "        for i in s:\n",
    "            if i.islower() and i.upper() in s:\n",
    "                tmp.append(i.upper())\n",
    "\n",
    "            elif i.isupper() and i.lower() in s:\n",
    "                tmp.append(i)\n",
    "\n",
    "        tmp.sort()\n",
    "        return tmp[-1] if tmp else \"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        hash_set = set(s)\n",
    "        res = ''\n",
    "        for i in reversed([chr(i) for i in range(97,123)]):\n",
    "            if i in hash_set and i.upper() in hash_set:\n",
    "                return i.upper()\n",
    "        return res\n",
    "\n",
    "                \n",
    "            \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        ans = ''\n",
    "        for ss in s:\n",
    "            if 'A' <= ss <= 'Z':\n",
    "                for sl in s:\n",
    "                    if sl == ss.lower():\n",
    "                        if not ans:\n",
    "                            ans = ss\n",
    "                        else:\n",
    "                            if ss > ans:\n",
    "                                ans = ss\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        a=''\n",
    "        for i in s:\n",
    "            if 'a'<=i<='z' and i.upper() in s:\n",
    "                if a==\"\" or i.upper() >a:\n",
    "                    a=i.upper()\n",
    "        return a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        tmp = [i for i in s if i != ' ']\n",
    "        res = sorted(tmp)\n",
    "        for i in range(len(res)-1,0,-1):\n",
    "            if res[i].upper() in res and res[i].islower():\n",
    "                return res[i].upper()\n",
    "        return \"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        lower = [chr(x) for x in range(97, 123)][::-1]\n",
    "        upper = [chr(x) for x in range(65, 91)][::-1]\n",
    "        for i in range(26):\n",
    "            if lower[i] in s and upper[i] in s:\n",
    "                return upper[i]\n",
    "        return ''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        s = set(s)\n",
    "        for lower, upper in zip(reversed(ascii_lowercase), reversed(ascii_uppercase)):\n",
    "            if lower in s and upper in s:\n",
    "                return upper\n",
    "        return \"\"\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        hash_set = set(s)\n",
    "        res = ''\n",
    "        for i in reversed([chr(i) for i in range(97,123)]):\n",
    "            if i in hash_set and i.upper() in hash_set:\n",
    "                return i.upper()\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        \n",
    "        temp = sorted(s, reverse=True)\n",
    "\n",
    "        for i in temp:\n",
    "            if i.islower() and i.upper() in s:\n",
    "                return i.upper()\n",
    "\n",
    "        return ''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        s = set(s)\n",
    "        for lower, upper in zip(reversed(ascii_lowercase), reversed(ascii_uppercase)):\n",
    "            if lower in s and upper in s:\n",
    "                return upper\n",
    "        return \"\"\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        a,b=[],[]\n",
    "        for i in s:\n",
    "            if i.isupper():\n",
    "                a.append(i)\n",
    "            else:\n",
    "                b.append(i)\n",
    "        ans=[]\n",
    "        for j in a:\n",
    "            if j.lower() in b:\n",
    "                ans.append(j)\n",
    "        if ans:\n",
    "            return max(ans)\n",
    "        return ''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        ss = set(s)\n",
    "        for c in ascii_uppercase[::-1]:\n",
    "            if c in ss and c.lower() in ss:\n",
    "                return c\n",
    "        return ''\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        x = ''\n",
    "        c = {}\n",
    "        for i in s:\n",
    "            if c.get(i.upper()):\n",
    "                if c[i.upper()] == 1 and 97<=ord(i)<=122:\n",
    "                    if not x or (x and ord(i.upper()) > ord(x)):\n",
    "                        x = i.upper()\n",
    "                if c[i.upper()] == 2 and 65<=ord(i)<=90:\n",
    "                    if not x or (x and ord(i.upper()) > ord(x)):\n",
    "                        x = i.upper()\n",
    "                print(c)\n",
    "            else:\n",
    "                if 97<=ord(i)<=122:\n",
    "                    c[i.upper()] = 2\n",
    "                else:\n",
    "                    c[i.upper()] = 1\n",
    "        if x:\n",
    "            return x\n",
    "        return ''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        ans1 = [0] * 26\n",
    "        ans2 = [0] * 26\n",
    "        for i in s:\n",
    "            if 'a' <= i <= 'z': ans1[ord(i) - ord('a')] = 1\n",
    "            else: ans2[ord(i) - ord('A')] = 1\n",
    "        for i in range(len(ans1)-1, -1, -1):\n",
    "            if ans1[i] == 1 and ans2[i] == 1:\n",
    "                return chr(ord('A')+i)\n",
    "        return ''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        res=\"\"\n",
    "        already_a=[]\n",
    "        already_A=[]\n",
    "        for i in s:\n",
    "            if i.islower():\n",
    "                if i.upper() in already_A:\n",
    "                    if not res:\n",
    "                        res=i.upper()\n",
    "                    if ord(res)<ord(i.upper()):\n",
    "                        res=i.upper()\n",
    "                else:\n",
    "                    already_a.append(i)\n",
    "            else:\n",
    "                if i.lower() in already_a:\n",
    "                    if not res:\n",
    "                        res=i\n",
    "                    if ord(res)<ord(i):\n",
    "                        res=i\n",
    "                else:\n",
    "                    already_A.append(i)\n",
    "        return res\n",
    "                    \n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        \n",
    "        temp = sorted(s, reverse=True)\n",
    "\n",
    "        for i in temp:\n",
    "            if i.islower() and i.upper() in s:\n",
    "                return i.upper()\n",
    "\n",
    "        return ''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        res=[]\n",
    "        for i in s:\n",
    "            if i.islower() and i.upper() in s:\n",
    "                res.append(i.upper())\n",
    "            elif i.isupper() and i.lower() in s:\n",
    "                res.append(i.upper())\n",
    "        res.sort()\n",
    "        if res:\n",
    "            return res[-1]\n",
    "        else:\n",
    "            return \"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        #alphabet_list = list(string.ascii_lowercase)\n",
    "        #alphabet_upper_list = list(string.ascii_uppercase)\n",
    "        ans = []\n",
    "        for ch in s:\n",
    "            if ch.upper() in s and ch.lower() in s:\n",
    "                ans.append(ch.upper())\n",
    "\n",
    "        if ans:\n",
    "            ans.sort()\n",
    "            return ans[-1]\n",
    "\n",
    "        return \"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        a=[\"A\",\"B\",\"C\",\"D\",\"E\",\"F\",\"G\",\"H\",\"I\",\"J\",\"K\",\"L\",\"M\",\"N\",\"O\",\"P\",\"Q\",\"R\",\"S\",\"T\",\n",
    "        \"U\",\"V\",\"W\",\"X\",\"Y\",\"Z\"]\n",
    "        b=[\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\",\"h\",\"i\",\"j\",\"k\",\"l\",\"m\",\"n\",\"o\",\"p\",\"q\",\"r\",\"s\",\"t\",\n",
    "        \"u\",\"v\",\"w\",\"x\",\"y\",\"z\"]\n",
    "        q=[]\n",
    "        p=[]\n",
    "        for i in range(len(s)):\n",
    "            if s[i] in a:\n",
    "                q.append(a.index(s[i]))\n",
    "            elif s[i] in b:\n",
    "                p.append(b.index(s[i]))\n",
    "        ma=[]\n",
    "        for i in q:\n",
    "            if i in p:\n",
    "                ma.append(i)\n",
    "        if ma:\n",
    "            return a[max(ma)]\n",
    "        return \"\"\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def greatestLetter(self, s: str) -> str:\n",
    "        ss = set(s)\n",
    "        for c in ascii_uppercase[::-1]:\n",
    "            if c in ss and c.lower() in ss:\n",
    "                return c\n",
    "        return ''\n",
    "\n"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
